package com.hrbxlh.actionImpl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.hrbxlh.dao.DepDao;
import com.hrbxlh.dao.LoginDao;
import com.hrbxlh.dao.MemberDao;
import com.hrbxlh.dao.RelStuClassDao;
import com.hrbxlh.dao.RelationDao;
import com.hrbxlh.dao.SourceDao;
import com.hrbxlh.dao.VirtualMachineManageDao;
import com.hrbxlh.util.pageUtil;
import com.hrbxlh.util.PubMethods;

/**
* -------------------------------------------------------
* Copyright (c) 2017, 鑫联华信息科技股份有限公司
* All rights reserved.
* FileName：MemberActionImpl.java
* Description：人员actionImpl类,负责操作人员数据以及逻辑处理。
* History：
* Date           Author               Desc
* 2017.1.6		  xzx                 建立
* -------------------------------------------------------
*/

@Component("memberActionImpl")
@Transactional
public class MemberActionImpl {
	
	@Resource(name = "memberDao")
	private MemberDao memberDao;
	
	@Resource(name = "relStuClassDao")
	private RelStuClassDao relStuClassDao;
	
	@Resource(name = "loginDao")
	private LoginDao loginDao;
	
	@Resource(name="depDao")
	private DepDao depDao;
	
	@Resource(name = "relationDao")
	private RelationDao relationDao;
	
	@Resource(name = "virtualMachineManageDao")
    private VirtualMachineManageDao virtualMachineManageDao;
	
	@Autowired
    @Qualifier("virtualMachineManageActionImpl")
    private VirtualMachineManageActionImpl virtualMachineManageActionImpl;
	
	@Resource(name="sourceDao")
	private SourceDao sourceDao;
	
	/**
	 * @description 添加人员的方法，参数key与数据库column对应即可。 
	 * @param Map<String,Object> paramMap
	 * @return Map<String, String> result true成功，false失败 errorMsg错误信息
	 * @throws Exception
	 */
	public Map<String, String> addMember(Map<String, Object> paramMap) throws Exception {
		System.out.println("参数"+paramMap);
		Map<String, String> resultMap = new HashMap<String, String>();
		boolean result = false;
		String failMsg = "";
		try {
			List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId((String)paramMap.get("stuorteaId"));
			//判断登录名重复
			if(memberList !=null && memberList.size() != 0){
				failMsg = "该用户已存在";
			}else{
				//查询当前人所填的部门是否已经存在
//				List<Map<String, Object>> depList = depDao.getDepList(paramMap);
//				if(depList==null||depList.size()==0){
//					//添加部门
//					depDao.addDep(paramMap);
//					System.out.println("能娶到新增的部门id吗"+paramMap.get("depId"));
//				}else{
//					paramMap.put("depId", depList.get(0).get("depId"));
//				}
				
				//添加人员
				memberDao.addMember(paramMap);
				//添加教师成绩设置
				Map<String,Object>  sourceMap = new HashMap<String,Object>();
				sourceMap.put("stuorteaId", paramMap.get("stuorteaId"));
				sourceMap.put("classPerformance", 0.4);
			    sourceMap.put("excellent", 4);
			    sourceMap.put("good", 3);
			    sourceMap.put("inso", 2);
			    sourceMap.put("bad", 1);
				sourceDao.addSorceSet(sourceMap);
				result = true;
			}
			
			if(!result){
				resultMap.put("errorMsg", failMsg);
			}
			resultMap.put("result", String.valueOf(result));
		} catch (Exception e) {
			throw e;
		}
		return resultMap;
	}
	
	/**
	 * @description 查询人员的方法
	 * @param Map<String,Object> paramMap,如果有参数，要与数据库column值相同。
	 * @return List<Map<String, Object>> 人员集合
	 * @throws Exception
	 */
	public List<Map<String, Object>> getMember(Map<String, Object> paramMap) throws Exception {

		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		try {
			resultList = memberDao.getMember(paramMap);
		} catch (Exception e) {
			throw e;
		}
		return resultList;
	}
	
	
	/**
	 * @description 修改人员的方法，参数key与数据库column一致。 
	 * @param Map<String,Object> paramMap
	 * @return boolean (true 成功 ,false失败)
	 * @throws Exception
	 */
	public boolean saveMember(Map<String,Object> paramMap) throws Exception {
		System.out.println("修改用户得到的参数是"+paramMap);
		boolean resultFlag = false;
		String password="";
		try {
			if((String)paramMap.get("password")!=""&&(String)paramMap.get("password")!=null){
				//密码加密
				String pwd = (String)paramMap.get("stuorteaId")+(String)paramMap.get("password");
				password = DigestUtils.md5Hex(pwd);
			}
			paramMap.put("password", password);
			memberDao.saveMember(paramMap);
			resultFlag = true;
		} catch (Exception e) {
			throw e;
		}
		return resultFlag;
	}
	
	
	/**
	 * @description 删除教师的方法，传的是每个人员的id。 
	 * @param .List<Integer> paramList 人员id集合
	 * @return boolean (true 成功 ,false失败)
	 * @throws Exception
	 */
	public Map<String,Object> delMember(List<String> paramList,HttpServletRequest request,int memType,int marks ) throws Exception {

		String resultFlag = "";
		Map<String,Object> returnMap = new HashMap<String,Object>();
		Map<String,Object> paraMap = new HashMap<String,Object>();
		System.out.println("参数是啥"+paramList);
		
		try {
			//获取当前登陆人的id
			String stuorteaId = (String) request.getSession().getAttribute("stuorteaId");
			//判断当前人是否删除的是自己
			for(int i=0;i<paramList.size();i++){
				if(stuorteaId.equals(paramList.get(i))){
					System.out.println("应该进1");
					resultFlag = "false";
					returnMap.put("resultFlag", resultFlag);
					returnMap.put("resultMsg", "当前用户正在使用");
				}else{
					
					//查询要删除人的角色
					List<Map<String, Object>> mem = memberDao.getMemberByStuorteaId(String.valueOf(paramList.get(i)));
					System.out.println("应该进2"+(Integer)mem.get(0).get("roleId")+" "+mem);
					if(memType==1||(Integer)mem.get(0).get("roleId")==2||(Integer)mem.get(0).get("roleId")==5){
						System.out.println("说明是删除教师");
						if(marks==1){
							//说明是删除教师,解绑
							paraMap.put("stuorteaId", paramList.get(i));
							//掉删除教师所有相关的方法
							returnMap = this.delTeaMethod(paramList,paraMap,marks);
						}if(marks==2){
							//说明是删除教师,删除
							paraMap.put("stuorteaId", paramList.get(i));
							try{
								virtualMachineManageActionImpl.deleteVirtualMachineTeacher(paraMap);
							}catch(Exception e){
								e.printStackTrace();
							}finally{
								System.out.println("删除删除");
								returnMap = this.delTeaMethod(paramList,paraMap,marks);
							}
						}
						
					}else if(memType==0&&(Integer)mem.get(0).get("roleId")!=2&&(Integer)mem.get(0).get("roleId")!=5&&(Integer)mem.get(0).get("roleId")!=1){
						System.out.println("说明删除的是管理员");
						//说明删除的是管理员
						//删除人与课程的关联表
						boolean flag = relStuClassDao.delRelstuCouByStuorteaId(paramList);
						//没有排课信息可以删除人员
						flag = memberDao.delMember(paramList);
						if(flag){
							returnMap.put("resultMsg", "成功");
							resultFlag = "true";
						}else{
							returnMap.put("resultMsg", "删除管理员失败");
							resultFlag = "false";
						}
						returnMap.put("resultFlag", resultFlag);
					}else if(memType==0&&(Integer)mem.get(0).get("roleId")==1){
						System.out.println("说明删除的是学生");
						//说明删除的是学生
						if(marks==1){
							//掉删除学生所有相关的方法
							returnMap = this.delStuMethod(paramList,marks);
						}if(marks==2){
							try{
								virtualMachineManageActionImpl.deleteVirtualMachineStudent(paraMap);
							}catch(Exception e){
								e.printStackTrace();
							}finally{
								
								returnMap = this.delStuMethod(paramList,marks);
								
							}
						}
					}
					
				}
			}
			
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}
	
	public Map<String,Object> delTeaMethod(List<String> paramList,Map<String,Object> paraMap,int marks ){
		String resultFlag = "";
		Map<String,Object> returnMap = new HashMap<String,Object>();
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		System.out.println("paraMap"+paraMap);
		try{
			//说明是删除教师
			//判断当前教师是否有排课信息
			resultList = relationDao.getRelStuCourseListById(paraMap);
			System.out.println("resultList"+resultList+resultList.size());
			if(resultList==null||resultList.size()==0){
				//删除人与课程的关联表
				boolean flag = relStuClassDao.delRelstuCouByStuorteaId(paramList);
				System.out.println("1");
				//删除班级与教师的关联表
				flag = relStuClassDao.delRelteaClassByStuOrTeaId(paramList);
				System.out.println("2");
				//删除班级与教师的关联表（刑新加的表）
				flag = relStuClassDao.delClassRelByStuOrTeaId(paramList);
				System.out.println("3");
				if(marks==1){
					System.out.println("6");
					//解除虚拟机分配，更改虚拟机的状态，使用者ID、主机/从机置空
					virtualMachineManageDao.unallocateVirtualMachine(paraMap);
					System.out.println("4");
					//删除教师分配的虚拟机
					virtualMachineManageDao.deleteVirtualMachineTeacher(paraMap);
					System.out.println("5");
				}
				//删除该教师所对应的成绩设置
				sourceDao.delSorceSetById(paraMap);
				System.out.println("7");
				//没有排课信息可以删除人员
				flag = memberDao.delMember(paramList);
				System.out.println("8"+flag);
				if(flag){
					returnMap.put("resultMsg", "成功");
					resultFlag = "true";
				}else{
					returnMap.put("resultMsg", "删除教师失败");
					resultFlag = "false";
				}
				
				returnMap.put("resultFlag", resultFlag);
			}else{
				returnMap.put("resultMsg", "此教师存在课程不可删除");
				resultFlag = "false";
				returnMap.put("resultFlag", resultFlag);
			}
		}catch(Exception e){
			
		}
		return returnMap;
	}
	
	public Map<String,Object> delStuMethod(List<String> paramList,int marks){
		String resultFlag = "";
		Map<String,Object> returnMap = new HashMap<String,Object>();
		Map<String,Object> paramMap = new HashMap<String,Object>();
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		try{
			//删除人与课程的关联表
			boolean flag = relStuClassDao.delRelstuCouByStuorteaId(paramList);
			//删除班级学生关联表
			flag =	relStuClassDao.delRelStuClassBySId(paramList);
			//删除学生成绩表
			flag =	sourceDao.delStuSoruceBystuorteaIdStu(paramList);
			//删除学生虚拟机
			if(marks==1){
				paramMap.put("stuorteaId", paramList.get(0));
				virtualMachineManageDao.unallocateVirtualMachine(paramMap);
			}
			//删除人员
			flag =	memberDao.delMember(paramList);
			if(flag){
				returnMap.put("resultMsg", "成功");
				resultFlag = "true";
			}else{
				returnMap.put("resultMsg", "删除学生失败");
				resultFlag = "false";
			}
			
			returnMap.put("resultFlag", resultFlag);
		}catch(Exception e){
			
		}
		return returnMap;
	}
	
	/**
	 * @description 查询人员列表的方法，分页。
	 * @param Map<String,Object> paramMap 当前页数：pageNow，每页条数：pageSize，其他条件与column列值要一致。
	 * @return Map<String, Object> memberList：人员集合，pageNow：当前页数，totalPage：总页数
	 * @throws Exception
	 */
	public Map<String, Object> getMemberList(Map<String, Object> paramMap) throws Exception {
		System.out.println("ROLE"+paramMap.get("roleId"));
		Map<String, Object> returnMap = new HashMap<String, Object>();
		try {
			int pageNow=0;
			int pageSize=10;
			if(paramMap.get("pageNow")!=null&&paramMap.get("pageSize")!=null){
				pageNow =(Integer)paramMap.get("pageNow");
				pageSize = (Integer)paramMap.get("pageSize");
			}
			
			if(pageNow!=0){
				//获取分页数据
//				pageNow = (Integer)paramMap.get("pageNow");
//				pageSize = (Integer)paramMap.get("pageSize");
				int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
				paramMap.put("startNum", startNum);
			}
			List<Map<String, Object>> memberList = memberDao.getMember(paramMap);
			returnMap.put("memberList", memberList);
			returnMap.put("pageNow", pageNow);
			
			//获取全部页数
			paramMap.put("pageNow", 0);
			List<Map<String, Object>> allMemberList = memberDao.getMember(paramMap);
			int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
			returnMap.put("totalPage", totalPage);
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}
	
	/**
	 * @description 通过学号/工号获取用户信息
	 * @param String 学号/工号
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public Map<String, Object> getMemberByLogName(String stuorteaId) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> memberList= memberDao.getMemberByStuorteaId(stuorteaId);
			if(memberList != null && memberList.size() !=0){
				returnMap = memberList.get(0);
			}
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}
	
	/**
	 * @description 登录的方法
	 * @param Map<String, Object> 
	 * @return Map<String, String>  
	 * @throws Exception
	 */
	public Map<String, Object> login(Map<String, Object> paramMap, HttpServletRequest request, HttpSession session) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		boolean resultFlag = false;
		String errorMsg = "";
		try {
			System.out.println("ddd"+paramMap.get("stuorteaId"));
			//通过学号/工号获取基本信息
			Map<String, Object> memberMessage = this.getMemberByLogName(String.valueOf(paramMap.get("stuorteaId")));
			System.out.println("怎么会为空"+memberMessage);
			//获取用户填写的值
			//没加密的密码
			String pwd = (String)paramMap.get("stuorteaId")+(String)paramMap.get("password");
			System.out.println("没加密的密码"+pwd);
			String writePassword = DigestUtils.md5Hex(pwd);
			System.out.println("加密后的密码"+writePassword);
		    String writeVerficateCode = (String)paramMap.get("verficateCode");
		    writeVerficateCode = writeVerficateCode.toLowerCase();
			//从session里面取到验证码
			Map<String,Object> sessionMap = PubMethods.getSessionValues(new String[]{"randomString"}, request);
			String verficateCode = (String)sessionMap.get("randomString");
			System.out.println("从session里获取"+verficateCode);
//		    String verficateCode = "123";
			System.out.println("选择的角色"+String.valueOf(paramMap.get("selecetRoleId")));
			verficateCode = (verficateCode != null) ? verficateCode.toLowerCase() : verficateCode;
			System.out.println("writeVerficateCode="+writeVerficateCode+"verficateCode="+verficateCode);
			if(!writeVerficateCode.equals(verficateCode)){
				errorMsg = "验证码输入错误";
				System.out.println("验证码输入错误");
			}else{
				if(memberMessage == null || memberMessage.get("stuorteaId") == null){
					errorMsg = "用户不存在";
					System.out.println("用户不存在");
				}else{
					if(!writePassword.equals((String)memberMessage.get("password"))){
						errorMsg = "密码错误";
						System.out.println("密码错误");
					}else{
						resultFlag = true;
						//将当前登陆时间插入Login表
						loginDao.addLogin(paramMap);
						//登陆后登陆表的主键
						long mainId = (Long) paramMap.get("mainId");
						System.out.println("登陆后登陆表的主键"+mainId);
						int  selecetRoleId = Integer.parseInt(String.valueOf(paramMap.get("selecetRoleId")));
						//将用户id，角色id存入session
						session.setAttribute("userName", memberMessage.get("userName"));
						session.setAttribute("realRoleId", memberMessage.get("roleId"));
						session.setAttribute("stuorteaId", memberMessage.get("stuorteaId"));
						session.setAttribute("roleId", selecetRoleId);
						session.setAttribute("userName", memberMessage.get("userName"));
						session.setMaxInactiveInterval(60*60);
						returnMap.put("memberMessage", memberMessage);
						session.setAttribute("mainId", mainId);
//						if(String.valueOf(paramMap.get("rememberMe")).equals("true")){
//							session.setAttribute("password", (String)paramMap.get("password"));
//						}
						
					}
				}
			}
			
			if(!resultFlag){
				returnMap.put("errorMsg", errorMsg);
			}
			returnMap.put("result", String.valueOf(resultFlag));
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}
	
	/**
	 * @description 修改密码
	 * @param Map<String, Object> 登录名，密码
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public boolean savePassword(Map<String, Object> paramMap) throws Exception {

		boolean flag = false;
		try {
			memberDao.savePassword(paramMap);
			flag = true;
		} catch (Exception e) {
			throw e;
		}
		return flag;
	}
	
	/**
	 * @description 跳转到主页需要的
	 * @param Map<String, Object> 
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> skipMain(HttpServletRequest request,HttpSession session) throws Exception{
		
		Map<String, Object> returnMap = new HashMap<String, Object>(); 
		Map<String, Object> preParamMap = new HashMap<String, Object>(); 
		//页面名
		String page = "";
		try{
			String roleId = (String) request.getSession().getAttribute("roleId");
			String stuorteaId = (String) request.getSession().getAttribute("stuorteaId");
			if(roleId.equals("1")||roleId.equals("2")){
				//通过学号查询当前学生的所学的课程（到时候粘到刑的课程表中）
				preParamMap.put("stuorteaId", stuorteaId);
				List<Map<String,Object>> courseList = memberDao.getCoruseByStuorteaId(preParamMap);
				//通过学号、当前时间查询当前登陆人的课表
				String nowTime = PubMethods.getNowTime(new Date());
				returnMap.put("courseList", courseList);
			}
			if(roleId.equals("1")){
				//进入学生主页、需要当前学生的课程、课表
				page = "pc/stuMain";
				
			}if(roleId.equals("2")){
				//进入教师主页
				page = "pc/teaMain";
			}if(roleId.equals("3")||roleId.equals("4")){
				//是管理员---进入排课主页
				page = "pc/adminMain";
			}
			returnMap.put("page", page);
			
		}catch(Exception e){
			throw e;
		}
		return returnMap;
	}

	/**
	 * @description 增加教师的简介和照片
	 * @param Map<String, Object> 简介，照片，教师Id
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public boolean updatImOrContent(Map<String, Object> paramMap) throws Exception {

		boolean flag = false;
		try {
			memberDao.updatImOrContent(paramMap);
			flag = true;
		} catch (Exception e) {
			throw e;
		}
		return flag;
	}
	
	/**
	 * @description 教师/学生信息页修改（包含上传图片和修改简介）
	 * @param Map<String, Object> 简介，照片，教师Id
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public boolean updateInfo(Map<String, Object> paramMap) throws Exception {

		boolean flag = false;
		String password = "";
		try {
			String pwd = (String)paramMap.get("password");
			if(!(pwd.equals("")) && pwd!=null){
				System.out.println("看你走不走这");
				//密码加密
				 pwd = (String)paramMap.get("stuorteaId")+(String)paramMap.get("password");
				password = DigestUtils.md5Hex(pwd);
			}
			paramMap.put("password", password);
			System.out.println("解没解密"+paramMap.get("password"));
			memberDao.updateInfo(paramMap);
			flag = true;
		} catch (Exception e) {
			throw e;
		}
		return flag;
	}
	
	/**
	 * @description 通过学号/工号获取用户信息
	 * @param String 学号/工号
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public Map<String, Object> getMemberByStuorteaId(String stuorteaId) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> memberList= memberDao.getMemberByStuorteaId(stuorteaId);
			if(memberList != null && memberList.size() !=0){
				returnMap = memberList.get(0);
			}else{
				returnMap = null;
			}
			System.out.println("查详情"+returnMap);
			resultMap.put("memberMap", returnMap);
			resultMap.put("resultFlag", "success");
		} catch (Exception e) {
			resultMap.put("resultFlag", "fail");
			throw e;
		}
		return resultMap;
	}
	
	/**
	 * @description 通过登录名获取人员信息（管理人员中用到的有部门关联）
	 * @param String 
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public Map<String, Object> getAdminByStuorteaId(String stuorteaId) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> memberList= memberDao.getAdminByStuorteaId(stuorteaId);
			if(memberList != null && memberList.size() !=0){
				returnMap = memberList.get(0);
			}else{
				returnMap = null;
			}
			System.out.println("查详情"+returnMap);
			resultMap.put("memberMap", returnMap);
			resultMap.put("resultFlag", "success");
		} catch (Exception e) {
			resultMap.put("resultFlag", "fail");
			throw e;
		}
		return resultMap;
	}
	
	/**xzx
	 * @description 添加学生
	 * @param String 
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public Map<String, Object> addStu(Map<String, Object> paramMap) throws Exception {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId((String)paramMap.get("stuorteaId"));
			//判断学号重复
			if(memberList !=null && memberList.size() != 0){
				resultMap.put("result", false);
				resultMap.put("failMsg", "已存在该学生");
			}else{
				//生成密码
				//将密码默认给6个0和工号/学号一起用MD5加密
				String pwd = (String)paramMap.get("stuorteaId")+"000000";
				String password = DigestUtils.md5Hex(pwd);
				paramMap.put("roleId", 1);
				paramMap.put("password", password);
				paramMap.put("depId", 0);
				paramMap.put("age", 0);
				paramMap.put("headIcon", "");
				paramMap.put("userContect", "");
				paramMap.put("imageUrl", "");
				paramMap.put("mem_type", 3);
				memberDao.addMember(paramMap);
				//添加这个学生与这个班级的关联信息
				relStuClassDao.addRelStuClass(paramMap);
				//查询这个班级对应的课程
		    	List<Map<String, Object>> courseList = relStuClassDao.getRelCourseByClassId(paramMap);
				if(courseList != null){
					if(courseList.size() != 0){
						//将该学生与这个班级现拥有的课程进行关联
						for(int i = 0; i < courseList.size(); i++){
							//构造参数
							courseList.get(i).put("stuorteaId", paramMap.get("stuorteaId"));
							courseList.get(i).put("selectMark", 1);
							//保存关联关系的
							relationDao.saveRelCourseTea(courseList.get(i));
						}
					}
				}
				resultMap.put("result", true);
			}
		} catch (Exception e) {
			resultMap.put("result", "fail");
			throw e;
		}
		return resultMap;
	}
	
	/**
	 * @description 重置密码
	 * @param Map<String, Object> 
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public Map<String, Object> resetPwd(Map<String, Object> paramMap) throws Exception {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorMsg = "";
		String result="false";
		try {
				//将密码默认给6个0和工号/学号一起用MD5加密
				String pwd = (String)paramMap.get("stuorteaId")+"000000";
				String password = DigestUtils.md5Hex(pwd);
				paramMap.put("password", password);
				boolean flag = memberDao.resetPwd(paramMap);
				if(flag){
					errorMsg = "重置成功";
					result="true";
				}else{
					errorMsg = "重置失败";
				}
				resultMap.put("result", result);
				resultMap.put("errorMsg", errorMsg);
			
		} catch (Exception e) {
			resultMap.put("result", "fail");
			throw e;
		}
		return resultMap;
	}
	
	/**
	 * @description 查询全部教师
	 * @param 
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public List<Map<String, Object>> getTeachers() throws Exception {

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			list = memberDao.getTeachers();
		} catch (Exception e) {
			throw e;
		}
		return list;
	}
	
	/**班级下的学生
	 * @description 查询人员列表的方法，分页。
	 * @param Map<String,Object> paramMap 当前页数：pageNow，每页条数：pageSize，其他条件与column列值要一致。
	 * @return Map<String, Object> memberList：人员集合，pageNow：当前页数，totalPage：总页数
	 * @throws Exception
	 */
	public Map<String, Object> getMemberByClassId(Map<String, Object> paramMap) throws Exception {
		System.out.println("ClassId"+paramMap.get("classId"));
		Map<String, Object> returnMap = new HashMap<String, Object>();
		try {
			int pageNow=0;
			int pageSize=10;
			if(paramMap.get("pageNow")!=null&&paramMap.get("pageSize")!=null){
				pageNow =(Integer)paramMap.get("pageNow");
				pageSize = (Integer)paramMap.get("pageSize");
			}
			
			if(pageNow!=0){
				//获取分页数据
				int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
				paramMap.put("startNum", startNum);
			}
			List<Map<String, Object>> memberList = memberDao.getMemberByClassId(paramMap);
			returnMap.put("memberList", memberList);
			returnMap.put("pageNow", pageNow);
			
			//获取全部页数
			paramMap.put("pageNow", 0);
			List<Map<String, Object>> allMemberList = memberDao.getMemberByClassId(paramMap);
			int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
			returnMap.put("totalPage", totalPage);
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}
	
	/**
	 * @description 用户详情
	 * @param String 学号/工号
	 * @return Map<String, Object> 
	 * @throws Exception
	 */
	public Map<String, Object> getMemberDetailById(Map<String, Object> paramMap) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		try {
			List<Map<String, Object>> memberList= memberDao.getMemberDetailById(paramMap);
			returnMap.put("memberList", memberList);
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}
	
}